<template>
    <div>
        <div class="editor-title">
            <span class="editor-title__name">{{ data.text }}</span>
            <div class="editor-title__sub-text">搜索热词和更多相关配置项请前往配置<span class="editor-sub-span" @click="toConfig">去配置</span>
            </div>
        </div>
        <div class="img-btn-con">
            <div class="cls-flex" style="padding-bottom: 1rem">
                <div class="label-con" style="flex: 1">背景颜色</div>
                <div>
                    <el-color-picker v-model="data.style.background" @change="color_change('background', '#fff')" />
                </div>
            </div>
            <div class="cls-between" style="padding-bottom: 1rem">
                <div class="label-con" style="flex: 1">框体样式</div>
                <div class="cls-between">
                    <div class="item-con" :class="data.style['shape'] == 'square' ? 'item-con-active' : ''"
                        @click="clickStyle('square')">方形</div>
                    <div class="item-con" :class="data.style['shape'] == 'round' ? 'item-con-active' : ''"
                        @click="clickStyle('round')">圆形</div>
                </div>
            </div>
            <div class="cls-between" style="padding-bottom: 1rem">
                <div class="label-con" style="flex: 1">文本位置</div>
                <div class="cls-between">
                    <div class="item-con" :class="data.style['aligen'] == 'left' ? 'item-con-active' : ''"
                        @click="clickAlign('aligen', 'left')">
                        居左
                    </div>
                    <div class="item-con" :class="data.style['aligen'] == 'center' ? 'item-con-active' : ''"
                        @click="clickAlign('aligen', 'center')">
                        居中
                    </div>
                </div>
            </div>
            <div class="editor-two__item" style="padding-bottom: 1rem">
                <div class="label-con" style="padding-bottom: 1rem">提示文字</div>
                <el-input v-model="data.style.placeholder" placeholder="输入提示文本内容" clearable />
            </div>
            <!-- <div class="cls-flex" style="padding-bottom: 1rem">
                <div class="label-con" style="flex: 1">框体颜色</div>
                <div class="cls-between">
                    <div
                        class="item-con"
                        :class="data.style['box_bg'] === '#f7f8fa' ? 'item-con-active' : ''"
                        @click="color_change('box_bg', '#f7f8fa')"
                    >
                        灰色
                    </div>
                    <div class="item-con" :class="data.style['box_bg'] === '#fff' ? 'item-con-active' : ''" @click="color_change('box_bg', '#fff')">
                        白色
                    </div>
                </div>
            </div> -->
            <div class="cls-flex" style="padding-bottom: 1rem">
                <div class="label-con">页面边距</div>
                <div style="flex: 1; padding-right: 1rem">
                    <el-slider v-model="data.rpxStyle['margin-left']" :max="max" @change="padding_change" />
                </div>
                <div style="width: 4rem">
                    <el-input v-model.number="data.rpxStyle['margin-left']" @input="padding_change" />
                </div>
            </div>
            <div class="cls-flex" style="padding-bottom: 1rem">
                <div class="label-con">上边距</div>
                <div style="flex: 1; padding-right: 1rem">
                    <el-slider v-model="data.rpxStyle['margin-top']" :min="0" :max="300" @change="mtt_change" />
                </div>
                <div style="width: 4rem">
                    <el-input v-model.number="data.rpxStyle['margin-top']" @input="mtt_change" />
                </div>
            </div>
            <div class="cls-flex" style="padding-bottom: 1rem">
                <div class="label-con">下边距</div>
                <div style="flex: 1; padding-right: 1rem">
                    <el-slider v-model="data.rpxStyle['margin-bottom']" :min="0" :max="300" @change="mtb_change" />
                </div>
                <div style="width: 4rem">
                    <el-input v-model.number="data.rpxStyle['margin-bottom']" @input="mtb_change" />
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { getCurrentInstance, ref } from "vue"
import { Picture, PictureRounded, Plus } from "@element-plus/icons-vue"

const { proxy } = getCurrentInstance()
const max = 30 // 最大值，适用于内外边距和圆角

/**
 * 商品搜索
 * @property {Object} pageData  页面数据
 */
const props = defineProps({
    data: {
        type: Object,
        default: {
            id: 6,
            type_name: "search",
            text: "商品搜索",
            style: {
                background: "#fff", // 背景颜色
                box_bg: "#f7f8fa", // 框体背景颜色，1是标准灰色，2是白色
                shape: "round", // 框体样式，可选值square
                aligen: "left", // 输入框内容对齐方式，可选值为 center right
            },
            data: {
                /**请求地址*/
                reqUrl: "",
                /**请求参数*/
                reqData: {},
                /* 当没有请求地址的时候，使用data数据 */
                data: "",
                custom_icon: "", // 自定义图标
            },
        },
    },
})

// 框体样式
const clickStyle = (type) => {
    props.data.style.shape = type
}

/**
 * 当点击清空颜色时，恢复默认颜色
 * @param {*} key 要修改的颜色字段
 * @param {*} color 默认颜色， 当key值为null时，恢复默认颜色
 */
const color_change = (key, color) => {
    if (!props.data.style[key]) {
        props.data.style[key] = color
    }
}

const clickAlign = (key, style) => {
    props.data.style[key] = style
}

// 页面边距变化
const padding_change = (val) => {
    val = val > max ? max : val
    props.data.rpxStyle["margin-left"] = props.data.rpxStyle["margin-right"] = Number(val)
}

// 上下边距
const mtt_change = (val) => {
    props.data.rpxStyle["margin-top"] = Number(val)
}
const mtb_change = (val) => {
    props.data.rpxStyle["margin-bottom"] = Number(val)
}


const toConfig = () => {
    window.open("#/Shop/Deco/DecoHotTerms", "_blank")
}
</script>

<style lang="less" scoped>
.editor-sub-span {
    margin-left: 10px;
    color: #4b93fa;
    cursor: pointer;
}

.item-con {
    color: #323232;
    padding: 7px 14px;
    border: 1px solid #ebedf0;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
}

.item-con-active {
    color: #4b93fa !important;
    background-color: #edf4ff !important;
    border: 1px solid #4b93fa;
}

.el-button+.el-button {
    margin-left: 0 !important;
}

.el-button {
    border-radius: 0 !important;
}

.label-con {
    flex: none;
    width: 82px;
    font-size: 14px;
    padding-right: 10px;
    color: #969799;

    .label-con__span {
        font-size: 13px;
        color: #999;
    }
}

.tip-con {
    font-size: 12px;
    color: #fff;
    background: rgba(0, 0, 0, 0.6);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2px;
    width: 60px;
    text-align: center;
}</style>
